<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    request.setAttribute("basePath", basePath);
%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>管理员管理</title>
    <link rel="stylesheet" href="${basePath}css/layui.css">
</head>
<body>

<div class="layui-col-md12">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>管理员管理&nbsp;&nbsp;<a class="layui-btn-xs layui-bg-red" href="/AdminServlet?action=add">添加</a></legend>
    </fieldset>
    <input type="hidden" name="action" value="query">
    <div class="layui-input-inline">
    </div>
    <table class="layui-hide" id="admin" lay-filter="admin"></table>
    <script type="text/html" id="adminBar">
        <a title="修改" class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></a>
        <a title="删除" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
    </script>
</div>
<script src="${basePath}js/layui.all.js" charset="utf-8"></script>
<script>
    layui.use('table', function () {
        var table = layui.table;
        table.render({
            elem: '#admin',
            cellMinWidth: 80,
            cols: [
                [{
                    type: 'checkbox'
                }, {
                    field: 'username',
                    title: '用户名',
                    sort: true,
                    align: 'center'
                }, {
                    field: 'nickname',
                    title: '姓名',
                    sort: true,
                    align: 'center'
                }, {
                    fixed: 'right',
                    title: '操作',
                    toolbar: '#adminBar',
                    align: 'center',
                    width: 160
                }]
            ],
            data: ${adminJson},
            page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'],
                groups: 5,
                first: '首页',
                last: '尾页'
            }
        });
        table.on('tool(admin)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                // layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('确定删除此条数据？', function (index) {
                    obj.del();
                    layer.close(index);
                    self.location = '/AdminServlet?action=delete&username=' + data.username;
                });
            } else if (obj.event === 'edit') {
                // layer.msg('ID：' + data.username + ' 的查看操作');
                self.location = '/AdminServlet?action=find&username=' + data.username;
            }
        });
    });
</script>
</body>
</html>
